<fieldset class="layui-elem-field">
	<legend>修改文章</legend>
	<div class="layui-field-box">
		<div class="site-text site-block">
			<form th:action="@{/admin/m/base/info/edit.gsp}" id="editForm" th:object="${result}" role="form" method="post" class="layui-form">
				<input th:field="*{id}" type="text" hidden="true" /> <input th:field="*{nodeId}" type="hidden" />
				<div class="layui-form-item">
					<label class="layui-form-label">文章标题：<span style="color: red">*</span></label>
					<div class="layui-input-block">
						<input maxlength="55" type="text" name="title" th:value="*{title}" lay-verify="title" placeholder="请输入文章标题" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">链接地址：</label>
					<div class="layui-input-block">
						<input th:field="*{linkPath}" lay-verify="linkPath" placeholder="请输入链接地址，http://" type="text" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">关键字：</label>
					<div class="layui-input-block">
						<input th:field="*{metaKeywords}" lay-verify="metaKeywords" placeholder="请输入关键字" type="text" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">描述：</label>
					<div class="layui-input-block">
						<textarea th:field="*{metaDescription}" lay-verify="metaDescription" placeholder="请输入描述" rows="3" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">排序：<span style="color: red">*</span></label>
						<div class="layui-input-inline">
							<input type="number" th:field="*{sortOrder}" min="1" max="100" lay-verify="sortOrder" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">发布日期：</label>
						<div class="layui-input-inline">
							<input type="text" lay-verify="publishTime" placeholder="yyyy-mm-dd" autocomplete="off" th:field="*{publishTime}" class="layui-input" onclick="layui.laydate({elem: this})">
						</div>
						<div class="layui-form-mid">-</div>
						<div class="layui-input-inline">
							<input type="text" lay-verify="offTime" placeholder="yyyy-mm-dd" autocomplete="off" th:field="*{offTime}" class="layui-input" onclick="layui.laydate({elem: this})">
						</div>
					</div>
				</div>
				<div id="formBuilderDiv"></div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="submit1">提交</button>
						<button type="button" class="layui-btn layui-btn-primary closeBtn">取消</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</fieldset>
<script th:inline="javascript">
    /*<![CDATA[*/
    var form = layui.form();
    
    //自定义验证规则
    form.verify({
        title : function(value) {
            if (value.length <= 0) {
                return '文章标题必填';
            } else if (value.length > 40) {
                return '这标题也太长了，最长40个字哦！';
            }
        },
        linkPath : function(value) {
            if (value.length > 0) {
                if(!/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/.test(value)){
                    return '链接格式不正确'
                }
            }
        },
        metaKeywords : function(value) {
            if (value.length > 100) {
                return '关键字不能太长哦，最长100字！'
            }
        },
        sortOrder : function(value) {
            if (value < 1 || value > 100) {
                return '排序需在1~100之间'
            }
        },
        metaDescription : function(value) {
            if (value.length > 140) {
                return '描述不能太长哦，最长140字！';
            }
        },
        publishTime : function(value) {
            if (value.length > 0) {
                if(!/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/.test(value)){
                    return '日期格式不正确';
                }
            }
        },
        offTime : function(value) {
            if (value.length > 0) {
                if(!/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/.test(value)){
                    return '日期格式不正确';
                }
            }
        }
    });
    
    $('.closeBtn').click(function() {
        var infoListUrl = /*[[@{/admin/m/base/info/infoList.gsp?nodeId={nodeId}(nodeId=${result.nodeId})}]]*/'';
        $("#infoContent").load(infoListUrl);
    });
    var result = /*[[${result}]]*/;
    formBuilder({
        ownerType : 'infoModel',
        ownerId : /*[[${result.infoModelId}]]*/'ownerId',
        valueOwnerId : /*[[${result.id}]]*/'id',
    }, result, function() {
        window.setInterval("form.render();", 1000);
    });
    /*]]>*/
</script>